﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Skynet.WebAdministracion.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:YesNoQuestion runat=server></{0}:YesNoQuestion>")]
    public class YesNoQuestion : CompositeControl
    {
        [Bindable(true)]
        [Category("Exams")]
        [DefaultValue("")]
        [Localizable(true)]
        public int NumberOfQuestion
        {
            get
            {
                int s = (int)ViewState["NumberOfQuestion"];
                return s;
            }
            set
            {
                ViewState["NumberOfQuestion"] = value;
            }
        }
        private TextBox _QuestionText;
        private RadioButton _YesRadio;
        private RadioButton _NoRadio;

        public string Question { get { return this._QuestionText.Text; } }
        public bool Answer { get { return this._YesRadio.Checked; } }


        
        protected override void CreateChildControls()
        {
            Table tb = new Table() {  };
            tb.CssClass = "YesNoQuestionTable";

            TableRow rowQuestion = new TableRow() { };
            TableRow rowQuestionText = new TableRow();
            TableRow rowAnswers = new TableRow();

            var cellQuestion = new TableCell() { ColumnSpan=2 };
            cellQuestion.Text = "Question " + this.NumberOfQuestion.ToString();

            rowQuestion.Cells.Add(cellQuestion);


            var cellQuestionText = new TableCell() { ColumnSpan=2};
            _QuestionText = new TextBox();
            cellQuestionText.Controls.Add(_QuestionText);
            rowQuestionText.Cells.Add(cellQuestionText);


            var tcyesrb = new TableCell() {  };
            this._YesRadio = new RadioButton() { Text="Yes", GroupName =  "QuestionGroup" + this.NumberOfQuestion.ToString()};
            
            tcyesrb.Controls.Add(_YesRadio);
            

            var tcnorb = new TableCell() {  };
            this._NoRadio = new RadioButton() { Text = "No", GroupName = "QuestionGroup" + this.NumberOfQuestion.ToString()};
            
            tcnorb.Controls.Add(_NoRadio);

            rowAnswers.Cells.Add(tcyesrb);
            rowAnswers.Cells.Add(tcnorb);


            tb.Rows.Add(rowQuestion);
            tb.Rows.Add(rowQuestionText);
            tb.Rows.Add(rowAnswers);
            
            
            
            this.Controls.Add(tb);
        }
        
    }
}
